﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using RemotingObj;

namespace WTClient {
    public partial class frmMain : Form {
        OneLinerRemotingObj oneLinerObj;
        ImagesRemotingObj imageObj;

        public frmMain() {
            InitializeComponent();
            //InitOnelinerConnection();
            InitImageConnection();
        }

        private void InitOnelinerConnection() {
            TcpChannel tcpChannel = new TcpChannel();
            ChannelServices.RegisterChannel(tcpChannel, false);
            Type requiredType = typeof(OneLinerRemotingObj);
            oneLinerObj = (OneLinerRemotingObj)Activator.GetObject(requiredType, "tcp://localhost:6947/OneLiner");
        }

        private void InitImageConnection() {
            TcpChannel tcpChannel = new TcpChannel();
            ChannelServices.RegisterChannel(tcpChannel, false);            
            Type requiredType = typeof(ImagesRemotingObj);
            imageObj = (ImagesRemotingObj)Activator.GetObject(requiredType, "tcp://localhost:6948/Images");
        }

        private void btnAdd_Click(object sender, EventArgs e) {            
            oneLinerObj.AddOneLiner(uiWindow.Text);
        }

        private void btnGet_Click(object sender, EventArgs e) {
            string content = oneLinerObj.GetSingleOneLiner();
            uiWindow.Text = content;
        }

        private void button1_Click(object sender, EventArgs e) {
            imageObj.SetImage(pictureBox1.Image);
        }

        private void button2_Click(object sender, EventArgs e) {
            pictureBox1.Image = null;
        }

    }
}
